/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.science_mono.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.science_mono.entity.TbScienceMono;
import com.thinkgem.jeesite.modules.science_mono.service.TbScienceMonoService;

/**
 * 专著Controller
 * @author hang
 * @version 2017-01-15
 */
@Controller
@RequestMapping(value = "${adminPath}/science_mono/tbScienceMono")
public class TbScienceMonoController extends BaseController {

	@Autowired
	private TbScienceMonoService tbScienceMonoService;
	
	@ModelAttribute
	public TbScienceMono get(@RequestParam(required=false) String id) {
		TbScienceMono entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbScienceMonoService.get(id);
		}
		if (entity == null){
			entity = new TbScienceMono();
		}
		return entity;
	}
	
	@RequiresPermissions("science_mono:tbScienceMono:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbScienceMono tbScienceMono, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbScienceMono> page = tbScienceMonoService.findPage(new Page<TbScienceMono>(request, response), tbScienceMono); 
		model.addAttribute("page", page);
		return "modules/science_mono/tbScienceMonoList";
	}

	@RequiresPermissions("science_mono:tbScienceMono:view")
	@RequestMapping(value = "form")
	public String form(TbScienceMono tbScienceMono, Model model) {
		model.addAttribute("tbScienceMono", tbScienceMono);
		return "modules/science_mono/tbScienceMonoForm";
	}

	@RequiresPermissions("science_mono:tbScienceMono:edit")
	@RequestMapping(value = "save")
	public String save(TbScienceMono tbScienceMono, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbScienceMono)){
			return form(tbScienceMono, model);
		}
		tbScienceMonoService.save(tbScienceMono);
		addMessage(redirectAttributes, "保存专著成功");
		return "redirect:"+Global.getAdminPath()+"/science_mono/tbScienceMono/?repage";
	}
	
	@RequiresPermissions("science_mono:tbScienceMono:edit")
	@RequestMapping(value = "delete")
	public String delete(TbScienceMono tbScienceMono, RedirectAttributes redirectAttributes) {
		tbScienceMonoService.delete(tbScienceMono);
		addMessage(redirectAttributes, "删除专著成功");
		return "redirect:"+Global.getAdminPath()+"/science_mono/tbScienceMono/?repage";
	}

}